﻿namespace FasadPattern.Composits
{
    using System;
    using FasadPattern.SerializeWorker;
    using FasadPattern.SerializeWorker.JSONObjects;

    public class Adress : IAssignable
    {
        #region Constructors

        public Adress()
            : this(0, string.Empty, string.Empty, string.Empty, 0)
        {
        }

        public Adress(int index, string country, string city, string street, int houseNumber)
        {
            this.Index = index;
            this.Country = country;
            this.City = city;
            this.Street = street;
            this.HouseNumber = houseNumber;
        }

        #endregion Constructors

        #region Properties

        public int Index { get; set; }

        public string Country { get; set; }

        public string City { get; set; }

        public string Street { get; set; }

        public int HouseNumber { get; set; }

        #endregion Properties

        #region IAssignable implementation

        /// <summary>
        /// Transfares content
        /// </summary>
        /// <param name="obj">Object to transfare</param>
        public void AssignTo(object obj)
        {
            if (obj == null)
                throw new ArgumentNullException();

            if (obj is Adress)
            {
                Adress a = obj as Adress;
                a.City = this.City;
                a.Country = this.Country;
                a.HouseNumber = this.HouseNumber;
                a.Index = this.Index;
                a.Street = this.Street;

                return;
            }

            if (obj is JSONObject)
            {
                JSONObject result = obj as JSONObject;
                JSONSerializer ser = new JSONSerializer();
                result.EncodedStreamList = ser.Serialize(this).EncodedStreamList;

                return;
            }

            throw new NotSupportedException();
        }

        #endregion
    }
}
